<!DOCTYPE html>
<html lang="en">
<head>
    {include file='public/meta'/}

    <!-------------开关按钮css-------------->
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">


    <link rel="stylesheet" href="__STATIC_URL__/static/css/addmchat.css"/>

    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>

    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/bootstrap-table/bootstrap-table.css"/>
    <script>

        $(document).ready(function () {
            if (location.hash) {
                $('a[href=' + location.hash + ']').tab('show');
            }
            $(document.body).on("click", "a[data-toggle]", function (event) {
                location.hash = this.getAttribute("href");
            });
        });
        $(window).on('popstate', function () {
            var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
            $('a[href=' + anchor + ']').tab('show');
        });
    </script>
</head>
<body>
{include file='public/header'/}
<!------------------导航-------------------------->
<section>
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading mgl15 mgr15">
            <ul class="breadcrumb">
                <li>
                    当前位置是&nbsp;:&nbsp;
                </li>
                <li><a href="#">门店管理</a></li>
                <li class="active" style="color: #02b87f;"> 电子发票设置</li>
            </ul>
        </div>
        <div class="panel panel-default mgl15 mgr15">
            <div class="panel-heading addCharts" style="backgroad:#ededed;">电子发票设置
            </div>
            <div class="panel-body">
                <form class="form-horizontal adminex-form" action="" method="post" id="efp" name="form"
                      enctype="multipart/form-data">
                    <ul id="myTab" class="nav nav-tabs">
                        <li class="active"><a href="#jichu" data-toggle="tab">基础信息</a></li>
                        <li><a href="#fpinfo" data-toggle="tab">发票信息</a></li>
                        <li><a href="#goodslist" data-toggle="tab">商品设置</a></li>
                        <li><a href="#kplist" data-toggle="tab">开票记录</a></li>
                    </ul>

                    <div id="myTabContent" class="tab-content" style="padding-top:15px;">
                        <div class="tab-pane fade in active" id="jichu">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">商户号：</label>
                                <div class="col-sm-10">
                                    <input type="hidden" value="{$machinfo['id']}" id="id" name="id">
                                    <input type="hidden" value="send" id="type" name="type">
                                    <input type="text" class="form-control ipt4" readonly="readonly"
                                           value="{$machinfo['sub_mch_id']}" id="mchid" name="mchid">
                                    <div>开通前请先确认商户号与商户平台已做MA授权</div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">s_pappid：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" id="efp_s_pappid"
                                           value="{$machinfo['efp_s_pappid']}" name="efp_s_pappid">
                                    <div>开票平台提供的唯一id</div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">商户联系电话：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_phone']}"
                                           id="efp_phone" name="efp_phone">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">开票超时时间（秒）：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_time_out']}"
                                           id="efp_time_out" name="efp_time_out">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">是否自动开票：</label>
                                <div class="col-sm-10" id="mdtz">
                                    <div class="switch switch-small" data-animated="true" id="efp_isauto"
                                         data-on-label="开启" data-off-label="关闭">
                                        <input type="checkbox" name="efp_isauto" value="Y" class="efp_isauto" checked/>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">支付开票入口：</label>
                                <div class="col-sm-10">
                                    <div class="switch switch-small" data-animated="true" id="efp_receipt"
                                         data-on-label="开启" data-off-label="关闭">
                                        <input type="checkbox" name="efp_receipt" value="Y" class="efp_receipt"
                                               checked/>
                                    </div>
                                </div>
                            </div>
                            <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 col-sm-2 control-label">是否自动开票：</label>-->
                            <!--<div class="col-sm-10">-->
                            <!--<input type="text" class="form-control ipt4" value="{$machinfo['efp_isauto']}"-->
                            <!--id="efp_isauto" name="efp_isauto">-->
                            <!--</div>-->
                            <!--</div>-->
                            <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 col-sm-2 control-label">是否开启开票入口：</label>-->
                            <!--<div class="col-sm-10">-->
                            <!--<input type="text" class="form-control ipt4" value="{$machinfo['efp_receipt']}"-->
                            <!--id="efp_receipt" name="efp_receipt">-->
                            <!--</div>-->
                            <!--</div>-->
                        </div>

                        <div class="tab-pane fade" id="fpinfo">
                            <div class="alert alert-info">以下信息为票面显示信息，务必填写正确。</div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">公司或商户全称：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_company']}"
                                           id="efp_company" name="efp_company">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">税号：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_invoice']}"
                                           id="efp_invoice" name="efp_invoice">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">开票机号（税控盘编号）：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_kpjh']}"
                                           id="efp_kpjh" name="efp_kpjh">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">联系地址：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_address']}"
                                           id="efp_address" name="efp_address">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">联系人：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_contact']}"
                                           id="efp_contact" name="efp_contact">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">联系电话：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control ipt4" value="{$machinfo['efp_tel']}"
                                           id="efp_tel" name="efp_tel">
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane fade" id="goodslist">
                            <table class="table table-hover">
                                <caption>商品列表</caption>
                                <span class="btn btn-success pull-right" id="addgoods"
                                      style="margin-top: -5px;">添加商品</span>

                                <thead>
                                <tr>
                                    <th>商品名称</th>
                                    <th>商品编码</th>
                                    <th>规格型号</th>
                                    <th>计量单位</th>
                                    <th>商品数量</th>
                                    <th>商品单价</th>
                                    <th>商品金额</th>
                                    <th>含税标志</th>
                                    <th>税率</th>
                                    <th>默认开票商品</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name="goodslist" id="vo"}
                                <tr>
                                    <td>{$vo['spmc']}</td>
                                    <td>{$vo['spbm']}</td>
                                    <td>{$vo['ggxh']}</td>
                                    <td>{$vo['jldw']}</td>
                                    <td>{$vo['spsl']}</td>
                                    <td>自动</td>
                                    <td>自动</td>
                                    <td>{$vo['hsbz']}</td>
                                    <td>{$vo['slv']}%</td>
                                    <td>{$vo['is_default']}</td>
                                    <td><a href="javascript:void(0)" onclick="modify({$vo['id']})">修改</a> | <a
                                            href="javascript:void(0)" onclick="del({$vo['id']})">删除</a></td>
                                </tr>
                                {/volist}

                                </tbody>
                            </table>

                            <div class="form-group">

                            </div>
                        </div>
                        <div class="tab-pane fade in" id="kplist">
                            <div class="panel mgl15 mgr15">
                                <div class="panel-heading addCharts" style="background:#ededed;">开票明细


                                    <a href="javascript:;" onclick="load();" class="btn btn-info"
                                       style="float: right;  margin-top: -7px;">点击下载</a>

                                </div>
                                <div class="panel-body">
                                    <table class="table table-bordered table-striped" id="tablelist">

                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div style="text-align: center">
                        <button type="button" onclick="addform()" class="btn btn-primary">保存设置</button>
                    </div>
                </form>
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改商品信息</h4>
            </div>
            <div class="modal-body">
                <form role="form" class="form-horizontal adminex-form" id="goods_form">
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">商品名称：</label>
                        <div class="col-sm-10">
                            <input type="hidden" class="form-control ipt4 goods_ipt" id="goods_id" name="goods_id">
                            <input type="hidden" class="form-control ipt4" id="mid" value="{$machinfo['id']}"
                                   name="mid">
                            <input type="hidden" class="form-control ipt4" value="goods" name="type">
                            <input type="text" class="form-control ipt4 goods_ipt" id="spmc" name="spmc">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">商品编码：</label>
                        <div class="col-sm-10">
                            <input type="text" minlength="30" maxlength="30" class="form-control ipt4 goods_ipt"
                                   id="spbm"
                                   name="spbm">
                            <div>请输入19位商品编码</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">规格型号：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 goods_ipt" id="ggxh" name="ggxh">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">计量单位：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 goods_ipt" id="jldw" name="jldw">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">商品数量：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 goods_ipt" id="spsl" name="spsl">
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                    <!--<label class="col-sm-2 col-sm-2 control-label">商品单价：</label>-->
                    <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control ipt4" id="spdj" name="address">-->
                    <!--</div>-->
                    <!--</div>-->
                    <!--<div class="form-group">-->
                    <!--<label class="col-sm-2 col-sm-2 control-label">商品金额：</label>-->
                    <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control ipt4" id="je" name="address">-->
                    <!--</div>-->
                    <!--</div>-->
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">税率%：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 goods_ipt" id="slv" name="slv">
                        </div>
                    </div>

                    <!--<div class="form-group">-->
                    <!--<label class="col-sm-2 col-sm-2 control-label">税额：</label>-->
                    <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control ipt4" id="se" name="address">-->
                    <!--</div>-->
                    <!--</div>-->
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">含税标志：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4 goods_ipt" id="hsbz" name="hsbz">
                            <div>含税标志 0 不含税 1 含税</div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">默认商品：</label>
                        <div class="col-sm-10">
                            <div class="switch switch-small" data-animated="true" id="is_default" data-on-label="是"
                                 data-off-label="否">
                                <input type="checkbox" name="is_default" value="Y" class="is_default"/>
                            </div>
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                    <!--<label class="col-sm-2 col-sm-2 control-label">默认商品：</label>-->
                    <!--<div class="col-sm-10">-->
                    <!--<input type="text" class="form-control ipt4 goods_ipt" id="is_default" name="is_default">-->
                    <!--</div>-->
                    <!--</div>-->
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="sendform()">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel2">开票明细</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered">
                    <tbody id="templateHtml"></tbody>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
<script src="__STATIC_URL__/static/js/template.js"></script>
<script id="modallist" type="text/html">

    <tr>
        <td>商品编码：</td>
        <td>商品名称：</td>
        <td>规格型号：</td>
        <td>计量单位：</td>
        <td>商品数量</td>
        <td>商品单价</td>
        <td>商品金额：</td>
        <td>税率：</td>
        <td>税额：</td>
        <td>含税标志：</td>
    </tr>
    {{each list as value index}}}
    <tr>

        <td>{{value.spbm}}</td>
        <td>{{value.spmc}}</td>
        <td>{{value.ggxh}}</td>
        <td>{{value.jldw}} </td>
        <td>{{value.spsl}} </td>
        <td>{{value.spdj}}</td>
        <td>{{value.je}}</td>
        <td>{{value.slv}}</td>
        <td>{{value.se}}</td>
        <td>{{value.hsbz}}</td>
    </tr>
    {{/each}}
</script>
<script src="__STATIC_URL__/static/bootstrap-table/bootstrap-table.js"></script>
<script src="__STATIC_URL__/static/bootstrap-table/bootstrap-table-zh-CN.js"></script>
<script src="/wntable.js?v=1"></script>

<script>
    $(function () {
        var efp_isauto = "{$machinfo['efp_isauto']}";
        var efp_receipt = "{$machinfo['efp_receipt']}";
        if (efp_isauto == "N") {
            $('#efp_isauto').bootstrapSwitch('setState', false);
        } else {
            $('#efp_isauto').bootstrapSwitch('setState', true);
        }
        if (efp_receipt == "N") {
            $('#efp_receipt').bootstrapSwitch('setState', false);
        } else {
            $('#efp_receipt').bootstrapSwitch('setState', true);
        }

        $('#addgoods').click(function () {
            $('.goods_ipt').val("");
            $('#is_default').bootstrapSwitch('setState', false);
            $('#myModal').modal('show');
        })
    })

    function load() {
        layer.msg('暂未开放');
        // $("#type").val("out_excel");
        //
        // $.ajax({
        //     url: "{:url('pay/paylog')}",
        //     data: $('#machform').serialize(),
        //     dataType: "json",
        //     async: false,
        //     type: "post",
        //     success: function (res) {
        //         window.location.href = res ;
        //     }
        // })
    }

    $(function () {
        var type = "kaipiaolist";
        var url = "{:url('')}";
        getcolumn(type, url)

    });


    //搜索
    function searchforms() {
        $("#tablelist").bootstrapTable('refresh');
    }

    function sendform() {
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: $('#goods_form').serialize(),

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    layer.msg('操作成功');
                    setTimeout("window.location.reload()", 1000)
                } else {
                    layer.msg('操作失败');
                }
            }

        })
    }

    function del(id) {
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: {
                'id': id,
                'type': "delgoods"
            },

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    layer.msg('操作成功');
                    setTimeout("window.location.reload()", 1000)

                } else {
                    layer.msg('操作失败');
                }
            }

        })
    }

    function getfpgoodsinfo(id) {
        var datas = {};

        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: {
                'id': id,
                'type': "getfpgoodsinfo"
            },

            success: function (data) {
                console.log(data);
                datas.list = data;
                var html = template('modallist', datas);
                $("#templateHtml").html(html);


            }

        });
        $('#myModal2').modal('show');
    }

    function mtfapiao(id) {
        var datas = {};

        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: {
                'id': id,
                'type': "mtfapiao"
            },

            success: function (data) {
                console.log(data);
                if (data.result_code == "SUCCESS") {
                    layer.msg('操作成功');
                    setTimeout("window.location.reload()", 1000)
                } else {
                    layer.msg('操作失败 : '+data.result_msg);
                }
            }

        });
    }

    function modify(id) {
        $('.goods_ipt').val("");
        $('#is_default').bootstrapSwitch('setState', false);
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: {
                'id': id,
                'type': "getgoodsinfo"
            },

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    param = data.goodsinfo;
                    $('#spmc').val(param.spmc);
                    $('#goods_id').val(param.id);
                    $('#spbm').val(param.spbm);
                    $('#ggxh').val(param.ggxh);
                    $('#jldw').val(param.jldw);
                    $('#spsl').val(param.spsl);
                    $('#slv').val(param.slv);
                    $('#hsbz').val(param.hsbz);
                    $('#is_default').val(param.is_default);
                    if (param.is_default == "Y") {
                        $('#is_default').bootstrapSwitch('setState', true);
                    } else {
                        $('#is_default').bootstrapSwitch('setState', false);
                    }

                } else {
                    layer.msg('获取资料失败');
                }
            }

        });
        $('#myModal').modal('show');
    }

    function addform() {
        $.ajax({
            type: "POST",
            url: "{:url('')}",
            cache: false,
            dataType: "json",
            async: false,
            data: $('#efp').serialize(),

            success: function (data) {
                if (data.result_code == "SUCCESS") {
                    layer.msg('操作成功');
                    setTimeout("window.location.reload()", 1000)
                } else {
                    layer.msg('操作失败');
                }
            }

        })


    }


</script>

</html>
